/**
 * 
 */
package ru.olympus.antonyhands.ao.server.item.util;

import ru.olympus.antonyhands.ao.server.item.CraftInfo;
import ru.olympus.antonyhands.ao.server.item.Item;
import ru.olympus.antonyhands.ao.shared.item.EItemsViewType;
import ru.olympus.antonyhands.ao.shared.util.StringPair;

import com.google.common.base.Function;

/**
 * @author AntonyHands
 * @since 09.03.2012
 */
public class ItemToStringPairTransformer implements Function<Item, StringPair> {

	private EItemsViewType _viewType;

	public ItemToStringPairTransformer(EItemsViewType viewType)
	{
		_viewType = viewType;
	}

	@Override
	public StringPair apply(Item item) {
		StringPair res = new StringPair();
		res.setKey(item.getCode());
		if (EItemsViewType.CRAFTABLE_WITH_CRAFT_LEVEL.equals(_viewType))
		{
			CraftInfo ci = item.getCraftInfo();
			if (ci == null)
				res.setValue(item.getTitle());
			else
				res.setValue(ci.getCraftLevel() + " - " + item.getTitle());
		}
		else
			res.setValue(item.getTitle());
		return res;
	}

}
